package org.example.controller;

import org.example.pojo.PackingRecord;
import org.example.service.PackingRecordService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
public class PackingRecordController {

    @Resource
    private PackingRecordService packingRecordService;

    @GetMapping("/")
    public String index(Integer regionId, Model model){
        model.addAttribute("regionId",regionId);
        model.addAttribute("pack",packingRecordService.select(regionId));
        return "index";
    }

    @GetMapping("/add")
    public String add(){
        return "add";
    }

    @PostMapping("/add")
    public String add(PackingRecord record){
        if (packingRecordService.add(record)!=0){
            return "redirect:/";
        }else {
            return "index";
        }
    }

    @RequestMapping("/update/{id}")
    @ResponseBody
    public int update(@PathVariable("id") Integer id){
        return packingRecordService.update(id);
    }
}
